package cn.myfirefly.core.listener;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

import javax.servlet.ServletContextEvent;

public class ContextLoaderListener extends org.springframework.web.context.ContextLoaderListener {
	
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		
		String url = event.getServletContext().getInitParameter("configProperties");
		try {
			//读取配置文件
			Properties pro = new Properties();
			InputStream in = this.getClass().getResourceAsStream(url);
			pro.load(in);
			Set<Object> set = pro.keySet();
			for (Object object : set) {
				event.getServletContext().setAttribute((String)object, pro.getProperty((String)object));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
